// 导入用户集合
const { PageRights } = require('../../../model/pageRights');

module.exports = async (req, res) => {
  const pageRightsList = await PageRights.find()
  let oneList = pageRightsList.filter(item => item.grade === 1)
  let secodList = pageRightsList.filter(item => item.grade === 2)
  oneList = oneList.map(item => {
    let list = secodList.filter(cItem => item._id.toString() === cItem.parentId.toString())
    if (list.length) {
      return {
        _id: item._id,
        grade: item.grade,
        title: item.title,
        path: item.path,
        children: list
      }
    } else {
      return item
    }
    
  })
  
  res.json({
      data: oneList
  })
}